package com.nulldev.util.uri.yt.rewrite;

import com.nulldev.util.math.MathUtil;

public class YoutubeMetadata {

	private String videoID;
	
	private String title, author, authorID;
	private long views, duration;
	
	private double rating;
	private long likes, dislikes;
	
	private final String[] tags;
	
	public YoutubeMetadata(final String videoID, final String title, final String author, final String authorID
			, final long views, final long duration, final double rating, final long likes, final long dislikes,
			final String[] tags) {
		this.videoID = videoID;
		this.title = title;
		this.author = author;
		this.authorID = authorID;
		this.views = views;
		this.duration = duration;
		this.rating = rating;
		this.likes = likes;
		this.dislikes = dislikes;
		this.tags = tags;
	}
	
	public static enum ThumbnailSizeOption {
		
		/**
		 * Maximum Res. <br>
		 * Usually up to 1280x720
		 */
		MAX_RES_DEAFULT("maxresdefault"),
		/**
		 * Standard Quality <br>
		 * Usually up to 640x480
		 */
		SD_DEFAULT("sddefault"),
		/**
		 * High Quality <br>
		 * Usually up to 480x360
		 */
		HQ_DEFAULT("hqdefault"),
		/**
		 * Medium Quality <br>
		 * Usually up to 320x180
		 */
		MQ_DEFAULT("mqdefault"),
		/**
		 * Small Thumbnail <br>
		 * 120x90
		 */
		THUMBNAIL("default")
		;
		
		private final String str;
		private ThumbnailSizeOption(final String str) {
			this.str = str;
		}
		
		public String getString() {
			return this.str;
		}
	}
	
	public String getThumbnail() {
		return this.getThumbnail(ThumbnailSizeOption.MAX_RES_DEAFULT);
	}
	
	public String getThumbnail(final ThumbnailSizeOption size) {
		return "http://i.ytimg.com/vi/" + this.videoID + "/" + size.getString() + ".jpg";
	}
	
	@Override
	public String toString() {
		return "YouTubeMetadata[title=" + this.title + ",author=" + this.author + ",authorID=" + this.authorID + 
				",duration=" + MathUtil.formatSecondsL(this.duration) + "]";
	}
}
